#include "audio.h"

#include <lauxlib.h>
#include <lua.h>
#include <lualib.h>

#ifdef _WIN32   // 包含 win32和win64
#    define LIB __declspec( dllexport )
#else
#    define LIB
#endif

static int c_audio_play( lua_State* L )
{
    const char* fileName = lua_tostring( L, 1 );
    bool        loop     = lua_toboolean( L, 2 );
    copi_audio_stop();
    copi_audio_play( fileName, loop );
    return 0;
}

static int c_audio_stop( lua_State* L )
{
    copi_audio_stop();
    return 0;
}

static void c_audio_close()
{
    copi_audio_close();
}

static void c_audio_open()
{
    copi_audio_open();
}

LIB int luaopen_audio( lua_State* L )
{
    c_audio_open();
    luaL_Reg a [] = { { "stop", c_audio_stop }, { "play", c_audio_play }, { NULL, NULL } };
    luaL_newlib( L, a );
    printf( "初始化audio模块" );
    return 1;
}
